//
//  ForgotPassWord.m
//  投融保
//
//  Created by 523 on 14-1-18.
//  Copyright (c) 2014年 木叶科技. All rights reserved.
//

#import "ForgotPassWord.h"
#import "MYWebService.h"
#import "ReSetPasswordVC.h"
@interface ForgotPassWord ()

@end

@implementation ForgotPassWord

extern NSString *key;

NSString *oldeBindPhone;
NSString *resetPduserName;

#pragma mark-   -----------状态栏底色------
- (UIStatusBarStyle)preferredStatusBarStyle
{
    [self.view setBackgroundColor:[UIColor blackColor]];
    return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden
{
    return NO;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    int scrollHeight=50;
    if (SCREEN_HEIGHT>480) {
        scrollHeight=100;
    }
    [self.bgScrollView setContentSize:CGSizeMake(640, SCREEN_HEIGHT-100)];
    self.bgScrollView.scrollEnabled=YES;
    [self.bgScrollView setShowsVerticalScrollIndicator:NO];
    self.txtUserName.leftView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 15, 44)];
    self.txtUserName.leftViewMode=UITextFieldViewModeAlways;
    self.txtUserID.leftView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 15, 44)];
    self.txtUserID.leftViewMode=UITextFieldViewModeAlways;

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//获取原手机
- (IBAction)btnSubmitAction:(UIButton *)sender {
//     NSString *strQueryUserInfoService=@"service=queryUserInfoService&userName=wangchenchen&certNo=500228198806076891";
    NSString *strQueryUserInfoService=[NSString stringWithFormat:@"service=queryUserInfoService&userName=%@&certNo=%@",self.txtUserName.text,self.txtUserID.text];
    MYWebService *service=[MYWebService new];
     MBProgressHUD *mbHud = [[MBProgressHUD alloc] initWithView:self.view];
    mbHud.labelText = @"正在发送";
    [self.view addSubview:mbHud];
    mbHud.delegate =self;
    [mbHud showAnimated:YES whileExecutingBlock:^{
        //z菊花转动的时候 开始加载数据
       [service getDataSynWithKey:key encryptedString:strQueryUserInfoService appKey:nil];
        
        

    } completionBlock:^{
        //执行加载数据完成后的操作。
        NSDictionary *resultDict=[service.profileDataSyn valueForKey:@"result"];
        if ([[resultDict valueForKey:@"code"] intValue]==1) {
            oldeBindPhone=[resultDict valueForKey:@"mobile"];
            resetPduserName=self.txtUserName.text;
//            [self presentModalViewController:[ReSetPasswordVC new] animated:NO];
            [self presentViewController:[ReSetPasswordVC new] animated:YES completion:nil];
            
        }else{
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"" message:[resultDict valueForKey:@"message"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil , nil];
            [alert show];
        }
        
    }];
#pragma mark- ---------仅供测试使用，用完删除
    
    
//    [self presentModalViewController:[ReSetPasswordVC new] animated:NO];
    
//    [self presentViewController:[ReSetPasswordVC new] animated:YES completion:nil];
    
}

- (IBAction)btnReturnAction:(UIButton *)sender {
//    [self dismissModalViewControllerAnimated:NO];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)closeKeyboard:(UITextField *)sender {
    [self.view endEditing:YES];
    [self.bgScrollView setContentOffset:CGPointMake(0, 0)];
    
}

#pragma mark +++++++++键盘+++++++++++
int prewTag ;  //编辑上一个UITextField的TAG,
float prewMoveY; //编辑的时候移动的高度
/**
 开始编辑UITextField的方法
 */
-(void) textFieldDidBeginEditing:(UITextField *)textField
{
    
    CGRect textFrame =  textField.frame;
    float textY = textFrame.origin.y+textFrame.size.height;
    float bottomY = self.bgScrollView.frame.size.height-textY;
    if(bottomY>=260)  //判断当前的高度是否已经有216，如果超过了就不需要再移动主界面的View高度
    {
        prewTag = -1;
        return;
    }
    prewTag = textField.tag;
    float moveY;
    if (SCREEN_HEIGHT>480) {
        moveY = 260-bottomY;
    }else
    {
        moveY = 300-bottomY;
    }
    
    prewMoveY = moveY;
    [UIView animateWithDuration:0.25 animations:^{
        [self.bgScrollView setContentOffset:CGPointMake(0, prewMoveY) animated:YES];
    }];
    
}

/**
 结束编辑UITextField的方法，让原来的界面还原高度
 */
-(void)textFieldDidEndEditing:(UITextField *)textField
{
    
    if(prewTag == -1) //当编辑的View不是需要移动的View
    {
        return;
    }
    float moveY ;
    
    if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
    {   //还原界面
        moveY =  prewMoveY;
        [self.bgScrollView setContentOffset:CGPointMake(0, moveY)];
    }
    
}

@end
